/**
 * @MockBusiModule.java  COPYRIGHT xiaojian
 * 
 * Created on 2017年7月11日 上午11:08:18
 */
package xj.toolkit.access;

import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

/**
 * 模拟一个业务模块。
 * 
 * @author <a href="mailto:cxj2000@gmail.com">xiaojian.cao</a>
 *
 */
public class MockBusiModule {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		ServerBootstrap bootstrap = new ServerBootstrap();
		bootstrap.group(new NioEventLoopGroup())
			.channel(NioServerSocketChannel.class)
			.localAddress("127.0.0.1", 8091)
			.childHandler(new ChannelInitializer() {

				@Override
				protected void initChannel(Channel ch) throws Exception {
					ChannelPipeline pipeline = ch.pipeline();
					pipeline.addLast("encoder", new MessageEncoder());
					pipeline.addLast("decoder", new MessageDecoder());
					pipeline.addLast("busiHanlder", new IOHandler());
				}
				
			})
			.option(ChannelOption.SO_BACKLOG, 10240)
			.option(ChannelOption.SO_REUSEADDR, true)
			.option(ChannelOption.SO_RCVBUF, 8 * 1024)
			.childOption(ChannelOption.SO_KEEPALIVE, true)
			.childOption(ChannelOption.TCP_NODELAY, true)
			.childOption(ChannelOption.SO_LINGER, -1);
		

        Channel c = bootstrap.bind().await().channel();
        
        Thread.sleep(300000 * 1000);
        c.close();
	}

	
}
